/******************************************************************************
** 
** Entab.
** 
** File name:	entab.c
** Compilation:	cc entab.c -o entab
** Execution:	./entab
** 
** Description:
** Reads the input, replaces every string that consists of only spaces with
** tabs and underline symbols to fit the same length.
** 
******************************************************************************/
#include <stdio.h>

#define MAX_LINE_LENGTH 1000
#define TAB_WIDTH 8
#define UNDERLINE_SYMBOL '_'
#define TAB_SYMBOL '|'
#define SPACE_SYMBOL ' '
#define NEWLINE_SYMBOL '\n'
#define ENDLINE_SYMBOL '\0'

int get_line(char line[], int max_length);
int if_line_only_spaces(char line[], int max_length);

int main()
{
    int i, length, n_spaces;
    char current_line[MAX_LINE_LENGTH];
    
    n_spaces = 0;
    while ((length = get_line(current_line, MAX_LINE_LENGTH)) != 0) {
        if (if_line_only_spaces(current_line, length) == 0) {
            printf("%s\n", current_line);
        } else {
            printf("%d: ", length-1);
            // assume that every line ends with '\n''\0'
            for (i=0; i<((length-1)/TAB_WIDTH); ++i) {
                printf("%c", TAB_SYMBOL);
            }
            for (i=0; i<((length-1)%TAB_WIDTH); ++i) {
                printf("%c", UNDERLINE_SYMBOL);
            }
            printf("\n\n");
        }
    }
    
    return 0;
}


// get_line: Reads one line from the input and stores it in the array, returns line length.
int get_line(char line[], int max_length) {
    int c, i;

    for (i=0; i<max_length && (c=getchar()) != EOF && c != NEWLINE_SYMBOL; ++i) {
        line[i] = c;
    }
    if (c == NEWLINE_SYMBOL) {
        line[i] = c;
        ++i;
    }
    line[i] = ENDLINE_SYMBOL;
    return i;
}


// if_line_only_spaces: Gets the line and its length, returns 1 if line conststs of only spaces (and '\n' of course), returns 0 if not.
int if_line_only_spaces(char line[], int length) {
    int i, if_space;
    
    if_space = 1;
    for (i=0; i<=length; ++i) {
        if ((line[i] != SPACE_SYMBOL) && (line[i] != NEWLINE_SYMBOL) && (line[i] != ENDLINE_SYMBOL)) {
            if_space = 0;
        }
    }
    
    return if_space;
}                                                    